package util;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import casino.Card;

public class CardValues{
	
	private static BufferedImage fronts = getFronts();
	
	public final static BufferedImage back = getBack();
	public final static int width = back.getWidth();
	public final static int height = back.getHeight();
	
	public static final Card ace_of_clubs = new Card(Value.ace, Suit.clubs, fronts.getSubimage(0, 0, 79, 123));
	public static final Card two_of_clubs = new Card(Value.two, Suit.clubs, fronts.getSubimage(79, 0, 79, 123));
	public static final Card three_of_clubs = new Card(Value.three, Suit.clubs, fronts.getSubimage(158, 0, 79, 123));
	public static final Card four_of_clubs = new Card(Value.four, Suit.clubs, fronts.getSubimage(237, 0, 79, 123));
	public static final Card five_of_clubs = new Card(Value.five, Suit.clubs, fronts.getSubimage(316, 0, 79, 123));
	public static final Card six_of_clubs = new Card(Value.six, Suit.clubs, fronts.getSubimage(395, 0, 79, 123));
	public static final Card seven_of_clubs = new Card(Value.seven, Suit.clubs, fronts.getSubimage(474, 0, 79, 123));
	public static final Card eight_of_clubs = new Card(Value.eight, Suit.clubs, fronts.getSubimage(553, 0, 79, 123));
	public static final Card nine_of_clubs = new Card(Value.nine, Suit.clubs, fronts.getSubimage(632, 0, 79, 123));
	public static final Card ten_of_clubs = new Card(Value.ten, Suit.clubs, fronts.getSubimage(711, 0, 79, 123));
	public static final Card jack_of_clubs = new Card(Value.jack, Suit.clubs, fronts.getSubimage(790, 0, 79, 123));
	public static final Card queen_of_clubs = new Card(Value.queen, Suit.clubs, fronts.getSubimage(869, 0, 79, 123));
	public static final Card king_of_clubs = new Card(Value.king, Suit.clubs, fronts.getSubimage(948, 0, 79, 123));
	public static final Card ace_of_diamonds = new Card(Value.ace, Suit.diamonds, fronts.getSubimage(0, 123, 79, 123));
	public static final Card two_of_diamonds = new Card(Value.two, Suit.diamonds, fronts.getSubimage(79, 123, 79, 123));
	public static final Card three_of_diamonds = new Card(Value.three, Suit.diamonds, fronts.getSubimage(158, 123, 79, 123));
	public static final Card four_of_diamonds = new Card(Value.four, Suit.diamonds, fronts.getSubimage(237, 123, 79, 123));
	public static final Card five_of_diamonds = new Card(Value.five, Suit.diamonds, fronts.getSubimage(316, 123, 79, 123));
	public static final Card six_of_diamonds = new Card(Value.six, Suit.diamonds, fronts.getSubimage(395, 123, 79, 123));
	public static final Card seven_of_diamonds = new Card(Value.seven, Suit.diamonds, fronts.getSubimage(474, 123, 79, 123));
	public static final Card eight_of_diamonds = new Card(Value.eight, Suit.diamonds, fronts.getSubimage(553, 123, 79, 123));
	public static final Card nine_of_diamonds = new Card(Value.nine, Suit.diamonds, fronts.getSubimage(632, 123, 79, 123));
	public static final Card ten_of_diamonds = new Card(Value.ten, Suit.diamonds, fronts.getSubimage(711, 123, 79, 123));
	public static final Card jack_of_diamonds = new Card(Value.jack, Suit.diamonds, fronts.getSubimage(790, 123, 79, 123));
	public static final Card queen_of_diamonds = new Card(Value.queen, Suit.diamonds, fronts.getSubimage(869, 123, 79, 123));
	public static final Card king_of_diamonds = new Card(Value.king, Suit.diamonds, fronts.getSubimage(948, 123, 79, 123));
	public static final Card ace_of_hearts = new Card(Value.ace, Suit.hearts, fronts.getSubimage(0, 246, 79, 123));
	public static final Card two_of_hearts = new Card(Value.two, Suit.hearts, fronts.getSubimage(79, 246, 79, 123));
	public static final Card three_of_hearts = new Card(Value.three, Suit.hearts, fronts.getSubimage(158, 246, 79, 123));
	public static final Card four_of_hearts = new Card(Value.four, Suit.hearts, fronts.getSubimage(237, 246, 79, 123));
	public static final Card five_of_hearts = new Card(Value.five, Suit.hearts, fronts.getSubimage(316, 246, 79, 123));
	public static final Card six_of_hearts = new Card(Value.six, Suit.hearts, fronts.getSubimage(395, 246, 79, 123));
	public static final Card seven_of_hearts = new Card(Value.seven, Suit.hearts, fronts.getSubimage(474, 246, 79, 123));
	public static final Card eight_of_hearts = new Card(Value.eight, Suit.hearts, fronts.getSubimage(553, 246, 79, 123));
	public static final Card nine_of_hearts = new Card(Value.nine, Suit.hearts, fronts.getSubimage(632, 246, 79, 123));
	public static final Card ten_of_hearts = new Card(Value.ten, Suit.hearts, fronts.getSubimage(711, 246, 79, 123));
	public static final Card jack_of_hearts = new Card(Value.jack, Suit.hearts, fronts.getSubimage(790, 246, 79, 123));
	public static final Card queen_of_hearts = new Card(Value.queen, Suit.hearts, fronts.getSubimage(869, 246, 79, 123));
	public static final Card king_of_hearts = new Card(Value.king, Suit.hearts, fronts.getSubimage(948, 246, 79, 123));
	public static final Card ace_of_spades = new Card(Value.ace, Suit.spades, fronts.getSubimage(0, 369, 79, 123));
	public static final Card two_of_spades = new Card(Value.two, Suit.spades, fronts.getSubimage(79, 369, 79, 123));
	public static final Card three_of_spades = new Card(Value.three, Suit.spades, fronts.getSubimage(158, 369, 79, 123));
	public static final Card four_of_spades = new Card(Value.four, Suit.spades, fronts.getSubimage(237, 369, 79, 123));
	public static final Card five_of_spades = new Card(Value.five, Suit.spades, fronts.getSubimage(316, 369, 79, 123));
	public static final Card six_of_spades = new Card(Value.six, Suit.spades, fronts.getSubimage(395, 369, 79, 123));
	public static final Card seven_of_spades = new Card(Value.seven, Suit.spades, fronts.getSubimage(474, 369, 79, 123));
	public static final Card eight_of_spades = new Card(Value.eight, Suit.spades, fronts.getSubimage(553, 369, 79, 123));
	public static final Card nine_of_spades = new Card(Value.nine, Suit.spades, fronts.getSubimage(632, 369, 79, 123));
	public static final Card ten_of_spades = new Card(Value.ten, Suit.spades, fronts.getSubimage(711, 369, 79, 123));
	public static final Card jack_of_spades = new Card(Value.jack, Suit.spades, fronts.getSubimage(790, 369, 79, 123));
	public static final Card queen_of_spades = new Card(Value.queen, Suit.spades, fronts.getSubimage(869, 369, 79, 123));
	public static final Card king_of_spades = new Card(Value.king, Suit.spades, fronts.getSubimage(948, 369, 79, 123));
	
	public static Card[] cards = {ace_of_clubs, ace_of_diamonds, ace_of_hearts, ace_of_spades,
						   		  two_of_clubs, two_of_diamonds, two_of_hearts, two_of_spades, 
						   		  three_of_clubs, three_of_diamonds, three_of_hearts, three_of_spades, 
						   		  four_of_clubs, four_of_diamonds, four_of_hearts, four_of_spades, 
						   		  five_of_clubs, five_of_diamonds, five_of_hearts, five_of_spades, 
						   		  six_of_clubs, six_of_diamonds, six_of_hearts, six_of_spades, 
						   		  seven_of_clubs, seven_of_diamonds, seven_of_hearts, seven_of_spades, 
						   		  eight_of_clubs, eight_of_diamonds, eight_of_hearts, eight_of_spades, 
						   		  nine_of_clubs, nine_of_diamonds, nine_of_hearts, nine_of_spades, 
						   		  ten_of_clubs, ten_of_diamonds, ten_of_hearts, ten_of_spades, 
						   		  jack_of_clubs, jack_of_diamonds, jack_of_hearts, jack_of_spades, 
						   		  queen_of_clubs, queen_of_diamonds, queen_of_hearts, queen_of_spades, 
						   		  king_of_clubs, king_of_diamonds, king_of_hearts, king_of_spades
								};
	
	public enum Value {
		ace,
		two,
		three,
		four,
		five,
		six,
		seven,
		eight,
		nine,
		ten,
		jack,
		queen,
		king;
	}

	public enum Suit {
		clubs,
		diamonds,
		hearts,
		spades;
	}
	
	private static BufferedImage getFronts(){
		try{
			return ImageIO.read(new File("images/cards.png"));
		}catch (IOException e){
			System.err.println("Graphics error: "+e);
			return null;
		}
	}
	
	private static BufferedImage getBack(){
		try{
			return ImageIO.read(new File("images/back.png"));
		}catch (IOException e){
			System.err.println("Graphics error: "+e);
			return null;
		}
	}
}
